Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate tests for model serialization to goldens. #244

Merged
merged 1 commit into from
Jul 22, 2024

Conversation

mihaimaruseac
Copy link
Collaborator

Summary

This is to ensure that whenever we change the model serialization code, it is much easier to update the tests. The changes should be more readable this way.

When code changes to request changes to the goldens, the author of the change will need to run a pytest command to update the files by passing a flag, then add the goldens to the PR (ideally via a new commit).

This also ensures that we can test all models in all scenarios, in a similar way. Thus, removed the tests for empty models that were just testing for empty manifest. Added a new model that only contains an empty file.

Release Note

NONE

Documentation

NONE

@mihaimaruseac mihaimaruseac requested review from a team as code owners July 22, 2024 14:25
@mihaimaruseac mihaimaruseac added this to the V1 release milestone Jul 22, 2024
mihaimaruseac added a commit to mihaimaruseac/model-transparency that referenced this pull request Jul 22, 2024
Similar to sigstore#241, there is a duplication in the directory traversal between serializing to a digest and serializing to a manifest. This time, both supported parallelism, so there is really no need for the duplication.

We make an abstract `ShardedFilesSerializer` class to contain the logic for the directory traversal and then create the better named `DigestSerializer` and `ManifestSerializer` for the two serializing classes.

This time, instead of trying extremely hard to match the old behavior for digest serialization, we just update the goldens. This means that this depends on sigstore#244.

We still had to update some other tests: since the hashes are computed only for files, we no longer differentiate between a model with an empty directory and a model where that empty directory is completely removed. This is a corner case and it is ok to do this.

In fact, ignoring empty directories is part of the optimization hinted at in sigstore#197.

Signed-off-by: Mihai Maruseac <mihaimaruseac@google.com>
@mihaimaruseac mihaimaruseac force-pushed the use-golden-tests branch 4 times, most recently from 1da2824 to b13682a Compare July 22, 2024 19:09
This is to ensure that whenever we change the model serialization code, it is much easier to update the tests. The changes should be more readable this way.

When code changes to request changes to the goldens, the author of the change will need to run a `pytest` command to update the files by passing a flag, then add the goldens to the PR (ideally via a new commit).

This also ensures that we can test all models in all scenarios, in a similar way. Thus, removed the tests for empty models that were just testing for empty manifest. Added a new model that only contains an empty file.

Signed-off-by: Mihai Maruseac <mihaimaruseac@google.com>
@mihaimaruseac mihaimaruseac merged commit c672c36 into sigstore:main Jul 22, 2024
20 checks passed
@mihaimaruseac mihaimaruseac deleted the use-golden-tests branch July 22, 2024 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants